# @Version        : 1.0
# @Update Time    : 2024/12/18 23:12
# @File           : dict_service.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息
from advanced_alchemy import service
from src import models
from src.crud.dict_repository import DictTypeRepo, DictDataRepo


class DictTypeService(
    service.SQLAlchemyAsyncRepositoryService[models.SysDictType, DictTypeRepo]
):
    """Author repository."""

    repository_type = DictTypeRepo

    async def get_options(self, keys) -> dict:
        dict_list = await super().list(
            models.SysDictType.dict_type.in_(keys), load=[models.SysDictType.dict_datas]
        )
        options = {}
        for item in dict_list:
            options[item.dict_type] = [
                {"label": i.dict_label, "value": i.dict_value} for i in item.dict_datas
            ]

        return options


class DictDataService(
    service.SQLAlchemyAsyncRepositoryService[models.SysDictData, DictDataRepo]
):
    """字典数据."""

    repository_type = DictDataRepo
